package com.aim.analysis.excel;

import com.aim.analysis.artifact.Strategy;
import com.aim.analysis.records.Game;
import com.aim.analysis.records.GameValueExtractor;
import com.aim.analysis.records.Hit;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.util.*;

/**
 * User: Avraham Shvartzon
 * Date: 12/15/14
 */
public class FgnHitReoprt extends HitReport {

    public FgnHitReoprt(String fileSuffix) {
        super(fileSuffix);
    }

    @Override
    protected void writeStatistic(XSSFWorkbook workbook, Collection<Hit> hitCollection) {

    }

    @Override
    protected int getNumOfGames() {
        return 3;
    }

    @Override
    protected List<Game> orderingGames(List<Game> gameList) {
        List<Game> orderedGames = new ArrayList<Game>(gameList);
        Collections.sort(orderedGames, gameComparator);
        return orderedGames;
    }

    private Comparator<Game> gameComparator = new Comparator<Game>() {
        @Override
        public int compare(Game o1, Game o2) {
            return order(o1).compareTo(order(o2));
        }

        private Integer order(Game game){
            Strategy s = game.getKey().strategy;
            switch (s){
                case HEATING_GAME: return 0;
                case FPA: return 1;
                case GPA: return 2;
                case NPA: return 3;
            }
            return 5;
        }
    };

    @Override
    protected String getGameSuffix(int i) {
        switch (i){
            case 0: return Strategy.FPA.name();
            case 1: return Strategy.GPA.name();
            case 2: return Strategy.NPA.name();
        }
        throw new RuntimeException("invalid game index - " + i);
    }

    protected List<GameValueExtractor> getGameExtractors() {
        List<GameValueExtractor> valueExtractors = new ArrayList<GameValueExtractor>();

        // header
        //valueExtractors.add(GameValueExtractor.partitionKey);
        valueExtractors.add(GameValueExtractor.gameDescription);
        valueExtractors.add(GameValueExtractor.gameNumber);

        //mechanical - actions & costs
        valueExtractors.add(GameValueExtractor.maintenance);
        valueExtractors.add(GameValueExtractor.minor);
        valueExtractors.add(GameValueExtractor.mechanicalCost);

        // Alerts
        valueExtractors.add(GameValueExtractor.numOfAlerts);

        valueExtractors.add(GameValueExtractor.numOfMaintenanceAfterAlert);
        valueExtractors.add(GameValueExtractor.numOfMalfunctionAfterAlert);
        valueExtractors.add(GameValueExtractor.firstEventAfterAlertDiff);

        // Alert Response
       // valueExtractors.add(GameValueExtractor.minResponseDelay);
       // valueExtractors.add(GameValueExtractor.maxResponseDelay);
       // valueExtractors.add(GameValueExtractor.meanResponseDelay);
        valueExtractors.add(GameValueExtractor.meanResponseDelay2);
        valueExtractors.add(GameValueExtractor.varResponseDelay2);
        valueExtractors.add(GameValueExtractor.minAlertRecommendedTime);
        valueExtractors.add(GameValueExtractor.maxAlertRecommendedTime);
        valueExtractors.add(GameValueExtractor.meanAlertRecommendedTime);

        //time
        valueExtractors.add(GameValueExtractor.mechanicalTime);
        valueExtractors.add(GameValueExtractor.freezeTime);

        //performance
        valueExtractors.add(GameValueExtractor.totalShutdown);
        valueExtractors.add(GameValueExtractor.totalCollision);
        valueExtractors.add(GameValueExtractor.totalFire);

        valueExtractors.add(GameValueExtractor.netScore);
        valueExtractors.add(GameValueExtractor.calculatedMechanicalCost);

        // score
        // valueExtractors.add(GameValueExtractor.score);
        valueExtractors.add(GameValueExtractor.calculatedScore);

        return valueExtractors;
    }
}
